import Vue from 'vue'
import Vuex from 'vuex'
import {login} from "@/api/user"
import createPersistedState from 'vuex-persistedstate';

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:""
  },
  getters: {
    TOKEN(state){
      return state.token;
    }
  },
  mutations: {
    SEND_TOKEN(state,value){
      state.token = value;
    }
  },
  actions: {
    USER_LOGIN(context,value){
        login(value).then(res=>{
          if(res.data.data){
            context.commit("SEND_TOKEN",res.data.data.token);
          }
        })
    }
  },
  modules: {
  },
  plugins: [createPersistedState({key: 'token'})]
})
